package com.cj.interceptor;

import com.cj.pojo.SysUser;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @Date
 * @Author
 * @Description 登录拦截器
 * @Version 1.0.0
 */
public class LoginInterceptor implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        HttpSession session = request.getSession();
        SysUser user = (SysUser)session.getAttribute("USER_SESSION");
        if (user==null){
            response.sendRedirect(request.getContextPath()+"/user/to_login");
            return false;
        }

        return true;
    }
}
